package com.javaweb.service.Impl;

import com.javaweb.dao.CategoryDao;
import com.javaweb.model.Category;
import com.javaweb.service.CategoryService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Wanghai
 * @date 2024/11/3
 */
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    CategoryDao categoryDao;

    @Override
    public boolean deleteCategoryById(String categoryId) {
        int rowsAffected = categoryDao.deleteById(categoryId);
        return rowsAffected > 0;
    }

    @Override
    public boolean addCategory(Category category) {
        category.setCreateTime(new java.util.Date()); // 设置创建时间
        category.setUpdateTime(new java.util.Date()); // 设置更新时间
        int rowsAffected = categoryDao.insert(category);
        return rowsAffected > 0;
    }

    @Override
    // 获取所有分类
    public List<Category> listAllCategories() {
        return categoryDao.findAllCategories();
    }


}
